home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database Designers / Rational Rose 2000 / Rational Setup.EXE / common / lib / Win32 / NetAdmin.pm < prev    next >
Text File  |  1998-11-15  |  9KB  |  362 lines

  1. package Win32::NetAdmin;
  2.  
  3. #
  4. #NetAdmin.pm
  5. #Written by Douglas_Lankshear@ActiveWare.com
  6. #
  7.  
  8. $VERSION = '0.06';
  9.  
  10. require Exporter;
  11. require DynaLoader;
  12.  
  13. die "The Win32::NetAdmin module works only on Windows NT" if(!Win32::IsWinNT() );
  14.  
  15. @ISA= qw( Exporter DynaLoader );
  16. # Items to export into callers namespace by default. Note: do not export
  17. # names by default without a very good reason. Use EXPORT_OK instead.
  18. # Do not simply export all your public functions/methods/constants.
  19. @EXPORT = qw(
  20.     DOMAIN_ALIAS_RID_ACCOUNT_OPS
  21.     DOMAIN_ALIAS_RID_ADMINS
  22.     DOMAIN_ALIAS_RID_BACKUP_OPS
  23.     DOMAIN_ALIAS_RID_GUESTS
  24.     DOMAIN_ALIAS_RID_POWER_USERS
  25.     DOMAIN_ALIAS_RID_PRINT_OPS
  26.     DOMAIN_ALIAS_RID_REPLICATOR
  27.     DOMAIN_ALIAS_RID_SYSTEM_OPS
  28.     DOMAIN_ALIAS_RID_USERS
  29.     DOMAIN_GROUP_RID_ADMINS
  30.     DOMAIN_GROUP_RID_GUESTS
  31.     DOMAIN_GROUP_RID_USERS
  32.     DOMAIN_USER_RID_ADMIN
  33.     DOMAIN_USER_RID_GUEST
  34.     FILTER_TEMP_DUPLICATE_ACCOUNT
  35.     FILTER_NORMAL_ACCOUNT
  36.     FILTER_INTERDOMAIN_TRUST_ACCOUNT
  37.     FILTER_WORKSTATION_TRUST_ACCOUNT
  38.     FILTER_SERVER_TRUST_ACCOUNT
  39.     SV_TYPE_WORKSTATION
  40.     SV_TYPE_SERVER
  41.     SV_TYPE_SQLSERVER
  42.     SV_TYPE_DOMAIN_CTRL
  43.     SV_TYPE_DOMAIN_BAKCTRL
  44.     SV_TYPE_TIMESOURCE
  45.     SV_TYPE_AFP
  46.     SV_TYPE_NOVELL
  47.     SV_TYPE_DOMAIN_MEMBER
  48.     SV_TYPE_PRINT
  49.     SV_TYPE_PRINTQ_SERVER
  50.     SV_TYPE_DIALIN
  51.     SV_TYPE_DIALIN_SERVER
  52.     SV_TYPE_XENIX_SERVER
  53.     SV_TYPE_NT
  54.     SV_TYPE_WFW
  55.     SV_TYPE_POTENTIAL_BROWSER
  56.     SV_TYPE_BACKUP_BROWSER
  57.     SV_TYPE_MASTER_BROWSER
  58.     SV_TYPE_DOMAIN_MASTER
  59.     SV_TYPE_DOMAIN_ENUM
  60.     SV_TYPE_SERVER_UNIX
  61.     SV_TYPE_SERVER_MFPN
  62.     SV_TYPE_SERVER_NT
  63.     SV_TYPE_SERVER_OSF
  64.     SV_TYPE_SERVER_VMS
  65.     SV_TYPE_WINDOWS
  66.     SV_TYPE_DFS
  67.     SV_TYPE_ALTERNATE_XPORT
  68.     SV_TYPE_LOCAL_LIST_ONLY
  69.     SV_TYPE_ALL
  70.     UF_TEMP_DUPLICATE_ACCOUNT
  71.     UF_NORMAL_ACCOUNT
  72.     UF_INTERDOMAIN_TRUST_ACCOUNT
  73.     UF_WORKSTATION_TRUST_ACCOUNT
  74.     UF_SERVER_TRUST_ACCOUNT
  75.     UF_MACHINE_ACCOUNT_MASK
  76.     UF_ACCOUNT_TYPE_MASK
  77.     UF_DONT_EXPIRE_PASSWD
  78.     UF_SETTABLE_BITS
  79.     UF_SCRIPT
  80.     UF_ACCOUNTDISABLE
  81.     UF_HOMEDIR_REQUIRED
  82.     UF_LOCKOUT
  83.     UF_PASSWD_NOTREQD
  84.     UF_PASSWD_CANT_CHANGE
  85.     USE_FORCE
  86.     USE_LOTS_OF_FORCE
  87.     USE_NOFORCE
  88.     USER_PRIV_MASK
  89.     USER_PRIV_GUEST
  90.     USER_PRIV_USER
  91.     USER_PRIV_ADMIN
  92. );
  93.  
  94. @EXPORT_OK = qw(
  95.     GetError
  96.     GetDomainController
  97.     GetAnyDomainController
  98.     UserCreate
  99.     UserDelete
  100.     UserGetAttributes
  101.     UserSetAttributes
  102.     UserChangePassword
  103.     UsersExist
  104.     GetUsers
  105.     GroupCreate
  106.     GroupDelete
  107.     GroupGetAttributes
  108.     GroupSetAttributes
  109.     GroupAddUsers
  110.     GroupDeleteUsers
  111.     GroupIsMember
  112.     GroupGetMembers
  113.     LocalGroupCreate
  114.     LocalGroupDelete
  115.     LocalGroupGetAttributes
  116.     LocalGroupSetAttributes
  117.     LocalGroupIsMember
  118.     LocalGroupGetMembers
  119.     LocalGroupGetMembersWithDomain
  120.     LocalGroupAddUsers
  121.     LocalGroupDeleteUsers
  122.     GetServers
  123.     GetTransports
  124.     LoggedOnUsers
  125.     GetAliasFromRID
  126.     GetUserGroupFromRID
  127.     GetServerDisks
  128. );
  129. $EXPORT_TAGS{ALL}= \@EXPORT_OK;
  130.  
  131. =head1 NAME
  132.  
  133. Win32::NetAdmin - manage network groups and users in perl
  134.  
  135. =head1 SYNOPSIS
  136.  
  137.     use Win32::NetAdmin;
  138.  
  139. =head1 DESCRIPTION
  140.  
  141. This module offers control over the administration of groups and users over a
  142. network.
  143.  
  144. =head1 FUNCTIONS
  145.  
  146. =head2 NOTE
  147.  
  148. All of the functions return FALSE (0) if they fail, unless otherwise noted.
  149. C<server> is optional for all the calls below. If not given the local machine is
  150. assumed.
  151.  
  152. =over 10
  153.  
  154. =item GetDomainController(server, domain, returnedName)
  155.  
  156. Returns the name of the domain controller for server.
  157.  
  158. =item GetAnyDomainController(server, domain, returnedName)
  159.  
  160. Returns the name of any domain controller for a domain that is directly trusted
  161. by the server.
  162.  
  163. =item UserCreate(server, userName, password, passwordAge, privilege, homeDir, comment, flags, scriptPath)
  164.  
  165. Creates a user on server with password, passwordAge, privilege, homeDir, comment,
  166. flags, and scriptPath.
  167.  
  168. =item UserDelete(server, user)
  169.  
  170. Deletes a user from server.
  171.  
  172. =item UserGetAttributes(server, userName, password, passwordAge, privilege, homeDir, comment, flags, scriptPath)
  173.  
  174. Gets password, passwordAge, privilege, homeDir, comment, flags, and scriptPath
  175. for user.
  176.  
  177. =item UserSetAttributes(server, userName, password, passwordAge, privilege, homeDir, comment, flags, scriptPath)
  178.  
  179. Sets password, passwordAge, privilege, homeDir, comment, flags, and scriptPath
  180. for user.
  181.  
  182. =item UserChangePassword(domainname, username, oldpassword, newpassword)
  183.  
  184. Changes a users password. Can be run under any account.
  185.  
  186. =item UsersExist(server, userName)
  187.  
  188. Checks if a user exists.
  189.  
  190. =item GetUsers(server, filter, userRef)
  191.  
  192. Fills userRef with user names if it is an array reference and with the user
  193. names and the full names if it is a hash reference.
  194.  
  195. =item GroupCreate(server, group, comment)
  196.  
  197. Creates a group.
  198.  
  199. =item GroupDelete(server, group)
  200.  
  201. Deletes a group.
  202.  
  203. =item GroupGetAttributes(server, groupName, comment)
  204.  
  205. Gets the comment.
  206.  
  207. =item GroupSetAttributes(server, groupName, comment)
  208.  
  209. Sets the comment.
  210.  
  211. =item GroupAddUsers(server, groupName, users)
  212.  
  213. Adds a user to a group.
  214.  
  215. =item GroupDeleteUsers(server, groupName, users)
  216.  
  217. Deletes a users from a group.
  218.  
  219. =item GroupIsMember(server, groupName, user)
  220.  
  221. Returns TRUE if user is a member of groupName.
  222.  
  223. =item GroupGetMembers(server, groupName, userArrayRef)
  224.  
  225. Fills userArrayRef with the members of groupName.
  226.  
  227. =item LocalGroupCreate(server, group, comment)
  228.  
  229. Creates a local group.
  230.  
  231. =item LocalGroupDelete(server, group)
  232.  
  233. Deletes a local group.
  234.  
  235. =item LocalGroupGetAttributes(server, groupName, comment)
  236.  
  237. Gets the comment.
  238.  
  239. =item LocalGroupSetAttributes(server, groupName, comment)
  240.  
  241. Sets the comment.
  242.  
  243. =item LocalGroupIsMember(server, groupName, user)
  244.  
  245. Returns TRUE if user is a member of groupName.
  246.  
  247. =item LocalGroupGetMembers(server, groupName, userArrayRef)
  248.  
  249. Fills userArrayRef with the members of groupName.
  250.  
  251. =item LocalGroupGetMembersWithDomain(server, groupName, userRef)
  252.  
  253. This function is similar LocalGroupGetMembers but accepts an array or
  254. a hash reference. Unlike LocalGroupGetMembers it returns each user name
  255. as C<DOMAIN\USERNAME>. If a hash reference is given, the function
  256. returns to each user or group name the type (group, user, alias etc.).
  257. The possible types are as follows:
  258.  
  259.   $SidTypeUser = 1;
  260.   $SidTypeGroup = 2;
  261.   $SidTypeDomain = 3;
  262.   $SidTypeAlias = 4;
  263.   $SidTypeWellKnownGroup = 5;
  264.   $SidTypeDeletedAccount = 6;
  265.   $SidTypeInvalid = 7;
  266.   $SidTypeUnknown = 8;
  267.  
  268. =item LocalGroupAddUsers(server, groupName, users)
  269.  
  270. Adds a user to a group.
  271.  
  272. =item LocalGroupDeleteUsers(server, groupName, users)
  273.  
  274. Deletes a users from a group.
  275.  
  276. =item GetServers(server, domain, flags, serverRef)
  277.  
  278. Gets an array of server names or an hash with the server names and the
  279. comments as seen in the Network Neighborhood or the server manager.
  280. For flags, see SV_TYPE_* constants.
  281.  
  282. =item GetTransports(server, transportRef)
  283.  
  284. Enumerates the network transports of a computer. If transportRef is an array
  285. reference, it is filled with the transport names. If transportRef is a hash
  286. reference then a hash of hashes is filled with the data for the transports.
  287.  
  288. =item LoggedOnUsers(server, userRef)
  289.  
  290. Gets an array or hash with the users logged on at the specified computer. If
  291. userRef is a hash reference, the value is a semikolon separated string of
  292. username, logon domain and logon server.
  293.  
  294. =item GetAliasFromRID(server, RID, returnedName)
  295.  
  296. =item GetUserGroupFromRID(server, RID, returnedName)
  297.  
  298. Retrieves the name of an alias (i.e local group) or a user group for a RID
  299. from the specified server. These functions can be used for example to get the
  300. account name for the administrator account if it is renamed or localized.
  301.  
  302. Possible values for C<RID>:
  303.  
  304.   DOMAIN_ALIAS_RID_ACCOUNT_OPS
  305.   DOMAIN_ALIAS_RID_ADMINS
  306.   DOMAIN_ALIAS_RID_BACKUP_OPS
  307.   DOMAIN_ALIAS_RID_GUESTS
  308.   DOMAIN_ALIAS_RID_POWER_USERS
  309.   DOMAIN_ALIAS_RID_PRINT_OPS
  310.   DOMAIN_ALIAS_RID_REPLICATOR
  311.   DOMAIN_ALIAS_RID_SYSTEM_OPS
  312.   DOMAIN_ALIAS_RID_USERS
  313.   DOMAIN_GROUP_RID_ADMINS
  314.   DOMAIN_GROUP_RID_GUESTS
  315.   DOMAIN_GROUP_RID_USERS
  316.   DOMAIN_USER_RID_ADMIN
  317.   DOMAIN_USER_RID_GUEST
  318.  
  319. =item GetServerDisks(server, arrayRef)
  320.  
  321. Returns an array with the disk drives of the specified server. The array
  322. contains two-character strings (drive letter followed by a colon).
  323.  
  324. =back
  325.  
  326. =cut
  327.  
  328. sub AUTOLOAD {
  329.     my($constname);
  330.     ($constname = $AUTOLOAD) =~ s/.*:://;
  331.     #reset $! to zero to reset any current errors.
  332.     $!=0;
  333.     my $val = constant($constname, @_ ? $_[0] : 0);
  334.     if ($! != 0) {
  335.     if ($! =~ /Invalid/) {
  336.         $AutoLoader::AUTOLOAD = $AUTOLOAD;
  337.         goto &AutoLoader::AUTOLOAD;
  338.     }
  339.     else {
  340.         ($pack,$file,$line) = caller;
  341.         die "Your vendor has not defined Win32::NetAdmin macro $constname, used in $file at line $line.";
  342.     }
  343.     }
  344.     eval "sub $AUTOLOAD { $val }";
  345.     goto &$AUTOLOAD;
  346. }
  347.  
  348. $SidTypeUser = 1;
  349. $SidTypeGroup = 2;
  350. $SidTypeDomain = 3;
  351. $SidTypeAlias = 4;
  352. $SidTypeWellKnownGroup = 5;
  353. $SidTypeDeletedAccount = 6;
  354. $SidTypeInvalid = 7;
  355. $SidTypeUnknown = 8;
  356.  
  357. bootstrap Win32::NetAdmin;
  358.  
  359. 1;
  360. __END__
  361.  
  362.